﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Futaba.SBus.Channels
{
	/// <summary>
	/// Resembles an S.BUS channel (ie. stick, slider or switch position)
	/// </summary>
	public class Channel : NotifyPropertyChangedBase
	{

		private string _internalDisplayName;
		/// <summary>
		/// The function/assignment of this channel
		/// </summary>
		[XmlAttribute("displayName")]
		public virtual string DisplayName
		{
			get { return _internalDisplayName; }
			set
			{
				if (Equals(_internalDisplayName, value))
					return;
				_internalDisplayName = value;
				RaisePropertyChanged(); //RaisePropertyChanged("DisplayName");
			}
		}

		private byte _internalChannelId;
		/// <summary>
		/// The S.Bus channel value of this channel. Must be unique
		/// </summary>
		[XmlAttribute("channelId")]
		public virtual byte ChannelId
		{
			get { return _internalChannelId; }
			set
			{
				if (Equals(_internalChannelId, value))
					return;
				_internalChannelId = value;
				RaisePropertyChanged(); //RaisePropertyChanged("ChannelId");
			}
		}

		private int? _internalCurrentValue;
		/// <summary>
		/// The current positional value of this channel, in percent (-155% to 155%) (not serialized)
		/// </summary>
		[XmlIgnore]
		public virtual int? CurrentValue
		{
			get { return _internalCurrentValue; }
			set
			{
				if (Equals(_internalCurrentValue, value))
					return;
				_internalCurrentValue = value;
				RaisePropertyChanged(); //RaisePropertyChanged("CurrentValue");
			}
		}

		/// <summary>
		/// Returns an informative string representation of this instance
		/// </summary>
		public override string ToString()
		{
			return string.Format("Channel {0:00} ({1}): {2}%", ChannelId, DisplayName, CurrentValue);
		}

	}
}
